// 上次启动时的用户信息
let userInfoHistory = uni.getStorageSync('userInfo') || {};
export const state = {
  //是否已经登录
  hasLogin: Boolean(Object.keys(userInfoHistory).length),
  //用户信息
  userInfo: userInfoHistory
};

export const getters = {
  userInfo(state) {
  	return state.userInfo;
  },
  hasLogin(state){
  	return state.hasLogin;
  }
};

export const mutations = {
  //储存用户信息
  setUserInfo(state, data) {
	  //原有的结合传来的参数
	  let _info = state.userInfo;
	  state.userInfo = Object.assign({}, _info, data);
	  //设置为已经登录
	  state.hasLogin = true;
	  console.log('state.userInfo',state.userInfo);
	// #ifdef H5
	window.sessionStorage.setItem('userInfo', JSON.stringify(state.userInfo));
	// #endif
	//存储最新的用户数据到本地持久化存储
	uni.setStorageSync('userInfo', state.userInfo);
  },
  // 退出APP
  emptyUserInfo(state) {
	state.hasLogin = false;
	let userName = state.userInfo.userName
	let password = state.userInfo.displayPassword
	state.userInfo = {};
	state.userInfo.userName = userName;
	state.userInfo.displayPassword = password;
	// #ifdef H5
	window.sessionStorage.removeItem("userInfo");
	// #endif
	uni.removeStorageSync("userInfo");
	// uni.setStorageSync('userInfo', {});
  }
};

export const actions = {
  
};
